#===istalismanplugin===
# -*- coding: utf-8 -*-

# $Revision: 63 $
# $Author: rchiganov@gmail.com $
# $Date: 2013-12-25 18:21:58 +0000 (Wed, 25 Dec 2013) $

#---------------------------------------------------------------------------------------------------

# Talisman plugin
# anek_plugin.py

#---------------------------------------------------------------------------------------------------

import re

#---------------------------------------------------------------------------------------------------

def dec(text):
    nobold = text.replace('<br />','').replace('<br>','').replace('&nbsp;', ' ').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('\t','').replace('||||:]','').replace('>[:\n','')    
    return nobold

def handler_anekdot(type, source, parameters):
	import urllib
	from xml.dom import minidom
	reklama = [u'*ROFL* :)', u':-D :-D :-D']
	u = urllib.urlopen('http://anekdot.odessa.ua/rand-anekdot.php')
	target = u.read()
	od = re.search('>',target)
	h1 = target[od.end():]
	h1 = h1[:re.search('<a href=',h1).start()]
	message = dec(h1)
	reply(type, source, u'Анекдот: \n' + unicode(message,'windows-1251') + u'\n * ' + random.choice(reklama) + u' *')

#---------------------------------------------------------------------------------------------------

register_command_handler(handler_anekdot, 'анекдот', [ 'все', 'фан' ], 11, 'Показывает случайный анекдот с ресурса http://anekdot.odessa.ua/\n Написал: Gigabyte\nИдея: ManGust', 'анекдот', ['анекдот'])

#---------------------------------------------------------------------------------------------------